SuperItemStack
这个类通过这些成员变量和函数,实现了对物品的自定义组件管理、物品使用逻辑以及物品操作等功能,使得物品的行为和属性可以被灵活地管理和扩展。
成员函数
成员函数 描述
constructor(source_instance: mc.ItemStack) 构造函数,初始化物品堆实例,包括原生物品堆实例、自定义组件和计时器。
get amount(): number 获取物品堆的数量。
get isStackable(): boolean 判断物品堆是否可堆叠。
get keepOnDeath(): boolean 判断物品在玩家死亡时是否保留。
get lockMode(): mc.ItemLockMode 获取物品的锁定模式。
get maxAmount(): number 获取物品堆的最大数量。
get nameTag(): string 获取物品的名称标签。
get type(): mc.ItemType 获取物品的类型。
get typeId(): string 获取物品的类型ID。
onSwitchIn(player: SuperPlayer) 当物品切换到玩家手中时,调用此方法。
onSwitchOut(player: SuperPlayer) 当物品从玩家手中切换出去时,调用此方法。
onHand(player: SuperPlayer) 物品在玩家手中的逻辑。
onAttack(player: SuperPlayer, target: SuperEntity) 物品被用于攻击时的逻辑。
onUse(player: SuperPlayer) 物品被使用时的逻辑。
onUseOn(player: SuperPlayer, block: mc.Block, blockFace: mc.Direction, faceLocation: mc.Vector3, isFirstEvent: boolean) 物品被用于方块时的逻辑。
onStartUse(player: SuperPlayer, useDuration: number) 物品开始使用时的逻辑。
onStopUse(player: SuperPlayer, block: mc.Block) 物品停止使用时的逻辑。
onItemRelease(player: SuperPlayer, useDuration: number) 物品被释放时的逻辑。
onItemComplete(player: SuperPlayer) 物品使用完成时的逻辑。
getItem(): mc.ItemStack 获取原生物品堆实例,如果不存在,返回undefined​。
clone(): mc.ItemStack 创建物品堆的精确副本,包括任何自定义数据或属性。
getCanDestroy(): string[] 获取物品可以破坏的方块类型列表。
getCanPlaceOn(): string[] 获取物品可以放置的方块类型列表。
getComponent<T extends keyof mc.ItemComponentTypeMap>(componentId: T): mc.ItemComponentTypeMap[T]|undefined 获取物品原生组件。
getComponents(): mc.ItemComponent[] 获取物品堆的所有组件。
getDynamicProperty(identifier: string): boolean | number | string | mc.Vector3 | undefined 获取动态属性。
getDynamicPropertyIds(): string[] 获取物品的所有动态属性标识符。
getDynamicPropertyTotalByteCount(): number 获取物品所有动态属性的总字节大小。
getLore(): string[] 获取物品的lore值(副显示字符串),如果物品没有lore,返回空数组。
getTags(): string[] 获取物品的标签列表。
hasComponent(componentId: string): boolean 判断物品堆是否具有指定的组件。
hasTag(tag: string): boolean 判断物品堆是否有特定的标签。
isStackableWith(itemStack: mc.ItemStack): boolean 判断物品堆是否可以与给定的物品堆堆叠。
matches(itemName: string, states?: Record<string, boolean | number | string>): boolean 匹配物品。
setCanDestroy(blockIdentifiers?: string[]): void 设置物品可以破坏的方块类型列表。
setCanPlaceOn(blockIdentifiers?: string[]): void 设置物品可以放置的方块类型列表。
setDynamicProperty(identifier: string, value?: boolean | number | string | mc.Vector3): void 设置动态属性。
setLore(loreList?: string[]): void 设置物品的lore值,如果传入undefined​,清除lore列表。
readCustomComponent() 从存储中读取并加载自定义组件。
saveCustomComponent() 保存自定义组件到存储。
addCustomComponent(identifier: string, options?: SuperComponentCreateOptions): boolean 添加一个新的自定义组件,如果添加成功,返回true​。
removeCustomComponent(identifier: string) 移除一个自定义组件。
getCustomComponent<C extends ItemSuperComponent>(identifier: string): C | undefined 获取一个自定义组件。
getCustomComponents(): ItemSuperComponent[] 获取所有自定义组件,如果没有组件,返回空数组。
clearDynamicProperties(): void 清除物品的所有动态属性。